package tp.pr4.gui;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.GridBagLayout;
import java.awt.event.ContainerAdapter;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JMenu;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Dimension;

public class MainWindow extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = -6937031334160866618L;
	private GameGUI _game;
	private PlayerPanel _player;
	private MapPanel _mapa;
	public MainWindow(GameGUI game) {
		setMinimumSize(new Dimension(750, 530));
		this._game=game;
		getContentPane().addContainerListener(new ContainerAdapter() {
			
		});
//--- PARA EVITAR UN NULLPOINTER
		_player = new PlayerPanel(this._game);
		_mapa = new MapPanel();
//---
		
		setTitle("Aventura Grafica");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{220, 514, 0};
		gridBagLayout.rowHeights = new int[]{142, 309, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
		getContentPane().setLayout(gridBagLayout);
		
		JPanel actions = new ActionPanel(this._game,this._player,this._mapa);
		GridBagConstraints gbc_actions = new GridBagConstraints();
		gbc_actions.insets = new Insets(0, 0, 5, 5);
		gbc_actions.fill = GridBagConstraints.BOTH;
		gbc_actions.gridx = 0;
		gbc_actions.gridy = 0;
		getContentPane().add(actions, gbc_actions);
		
		//DEBERIA IR AQUI _player
		GridBagConstraints gbc_player = new GridBagConstraints();
		gbc_player.fill = GridBagConstraints.BOTH;
		gbc_player.insets = new Insets(0, 0, 5, 0);
		gbc_player.gridx = 1;
		gbc_player.gridy = 0;
		getContentPane().add(_player, gbc_player);
		
		
		GridBagConstraints gbc_mapa = new GridBagConstraints();
		gbc_mapa.gridwidth = 2;
		gbc_mapa.fill = GridBagConstraints.BOTH;
		gbc_mapa.gridx = 0;
		gbc_mapa.gridy = 1;
		getContentPane().add(_mapa, gbc_mapa);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnFile = new JMenu("File");
		
		
		menuBar.add(mnFile);
		
		JMenuItem mntmExit = new JMenuItem("Exit");
		mntmExit.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			}
			
		});
		mnFile.add(mntmExit);
	}
}